package com.my.library.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.my.library.entity.User;
import com.my.library.service.impl.BookServiceImpl;

@Controller
@RequestMapping("/book")
public class BookController extends AbstractController {
	
	@Resource
	private BookServiceImpl bookService;
	
	@RequestMapping(value="/getData", produces="text/xml;charset=UTF-8")
	@ResponseBody()
	public String getData(HttpSession session, int appId) {
		User u = (User) session.getAttribute("user");
		return bookService.getData(u.getRoles(), appId);
	}
	
	@RequestMapping(value="/delete", produces="text/plain;charset=UTF-8")
	@ResponseBody
	public String delete(int id){
		bookService.delete(id);
		return "删除成功";
	}
	
	@RequestMapping(value="/addInput", produces="application/json;charset=UTF-8")
	@ResponseBody
	public Object addInput(HttpSession session){
		User u = (User) session.getAttribute("user");
		return bookService.add(u.getRoles());
	}
}
